/*package com.yihaodian.search.core;

import java.io.IOException;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;

import proj.zoie.api.Zoie;
import proj.zoie.api.ZoieIndexReader;

import com.yihaodian.search.searcher.Searcher;


public class ZoieSearcherFactory<R extends IndexReader>{
	
	private static Logger logger = Logger.getLogger(ZoieSearcherFactory.class);
	
	private Zoie<R,?> _zoie;
	
	private IndexReader indexReader;
	
	private List<ZoieIndexReader<R>> zoieReaderList;
	
	public ZoieSearcherFactory(Zoie<R, ?> zoie){
		_zoie=zoie;
	}
	
	public Searcher getSearcher(){
		try {
			List<ZoieIndexReader<R>> readList=_zoie.getIndexReaders();
			if(readList!=zoieReaderList){
				synchronized (this) {
					if(readList!=zoieReaderList){
						if(indexReader!=null && indexReader.getRefCount()==1){
							indexReader.close();
						}
						zoieReaderList = readList;
						indexReader = new MultiReader(
								readList.toArray(new IndexReader[readList.size()]),false);
					}
				}
			}
			indexReader.incRef();
			return new ZoieSearcher<R>(this,null,indexReader);
		} catch (Throwable e) {
			logger.error(e.getMessage(), e);
		}		
		return null;
	}
	
	public void decRefReader(IndexReader reader){
		if(reader!=null){
			try {
				reader.decRef();
				if(reader.getRefCount()==1&& !reader.equals(indexReader)){
					synchronized(this){
						if(reader.getRefCount()==1&& !reader.equals(indexReader)){
							reader.close();
						}
					}
				}
//				if(reader instanceof MultiReader){
//					MultiReader multiReader=(MultiReader) reader;
//					IndexReader[] subReaders=multiReader.getSequentialSubReaders();
//					if(subReaders instanceof ZoieIndexReader[]){
//						ZoieIndexReader<R>[] zoieReaders = (ZoieIndexReader<R>[]) subReaders;
//						List<ZoieIndexReader<R>> readerList=Arrays.asList(zoieReaders);
//						_zoie.returnIndexReaders(readerList);					
//					}
//				}
				
			} catch (IOException e) {
				logger.error(e.getMessage(), e);
			}
			
		}
	}

}
*/